
#include <stdio.h>
#include <system/application.h>
#include <graphics/sprite.h>
#include <maths/vector2.h>
#include <maths/vector3.h>
#include <vector>
#include <graphics/mesh_instance.h>
#include <graphics/vita/texture_vita.h>
#include <graphics/model.h>

#include "GameState.h"
#include "MenuState.h"



MenuState::MenuState(const abfw::Platform& platform): mLoading(false), mFinishedLoading(false)
{
	mFont = new abfw::Font();
	mFont->Load("comic_sans", platform);

	mInputManager = platform.CreateSonyControllerInputManager();
}

MenuState::~MenuState()
{
	delete mInputManager;
}

GameStates::State MenuState::Update() 
{						
	//-- Game can only start if the first marker is found
	if (mARCardFound[0])
	{
		if (mLoading == true)
		{
			//-- Return the load state and load the game
			mFinishedLoading = true;
			mLoading = false;
			return GameStates::LOADSTATE;
		}

		if (mFinishedLoading)
		{
			//-- Return the play state
			return GameStates::PLAYSTATE;
		}

	}

	return GameStates::MENUSTATE;
}

void MenuState::Draw2D(abfw::SpriteRenderer* render, abfw::Matrix44 Projection) 
{

	if(mFont)
	{
		//-- Display all menu text
		mFont->RenderText(render, abfw::Vector3(190.0f, 50.0f, -0.9f), 3.0f, 0xff0000ff, abfw::TJ_LEFT, "Space Commander");
		mFont->RenderText(render, abfw::Vector3(480.0f, 350.0f, -0.9f), 1.0f, 0xff0000ff, abfw::TJ_CENTRE, "Left Analogue Stick: Move");
		mFont->RenderText(render, abfw::Vector3(480.0f, 390.0f, -0.9f), 1.0f, 0xff0000ff, abfw::TJ_CENTRE, "Right Analogue Stick: Aim");
		mFont->RenderText(render, abfw::Vector3(480.0f, 440.0f, -0.9f), 1.0f, 0xff0000ff, abfw::TJ_CENTRE, "Right Shoulder Button: Shoot");

		if (!mARCardFound[0])
		mFont->RenderText(render, abfw::Vector3(320.0f, 242.0f, -0.9f), 1.0f, 0xffffffff, abfw::TJ_LEFT, "Aim PSVita Towards Marker 1");
		else
		{
			if (!mFinishedLoading)
			mLoading = true;
			mFont->RenderText(render, abfw::Vector3(480.0f, 202.0f, -0.9f), 1.0f, 0xffffffff, abfw::TJ_CENTRE, "Please Keep PSVita Aiming at Marker 1");
			mFont->RenderText(render, abfw::Vector3(480.0f, 242.0f, -0.9f), 1.0f, 0xffffffff, abfw::TJ_CENTRE, "Loading...");
		}
	}

}
void MenuState::Draw3D(abfw::Renderer3D* render, abfw::Colour defaultColour) 
{
	
}
